package com.leoman.controller.backend;

import com.leoman.common.DataTableFactory;
import com.leoman.controller.common.CommonController;
import com.leoman.entity.FeedBack;
import com.leoman.service.FeedBackService;
import com.leoman.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 意见反馈管理
 * Created by 涂奕恒 on 2016/10/30.
 */
@Controller
@RequestMapping(value = "backend/feedBack")
public class FeedBackController extends CommonController {

    @Autowired
    private FeedBackService feedBackService;

    @RequestMapping("index")
    public String index() {
        return "backend/意见反馈列表";
    }

    @RequestMapping("/list")
    public void list(HttpServletResponse response,
                     String mobile,
                     String startTime,
                     String endTime,
                     Integer draw,
                     Integer start,
                     Integer length) {
        if (null == start || start == 0) {
            start = 1;
        }
        int pageNum = getPageNum(start, length);
        Page<FeedBack> page = feedBackService.pageByParams(mobile, startTime, endTime, pageNum, length);

        Map<String, Object> result = DataTableFactory.fitting(draw, page);
        WebUtil.printJson(response, result);
    }

    /**
     * 删除意见反馈
     *
     * @param feedBackId 意见反馈ID
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Integer delete(Integer feedBackId) {
        try {
            return feedBackService.delete(feedBackId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 批量删除意见反馈
     *
     * @param ids 意见反馈ID
     * @return
     */
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Integer batchDelete(String ids) {
        try {
            return feedBackService.batchDelete(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
}
